home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / wink24h / src / edit2.c < prev    next >
Text File  |  1994-06-01  |  40KB  |  1,632 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <ctype.h>
  4. #include    "defs.h"
  5. #include    "key.h"
  6. #include    "kkstr2.h"
  7. /* ------------------ New file  91.10.12 Pumpkin ---------------- */
  8. #include    <msdos.cf>
  9. #include    <dos.h>
  10. extern int  diskReady(int drive);
  11. /* -------------------------------------------------------------- */
  12. /* ------------------ SIDEWORK 92.01.31 Pumpkin -------------- */
  13. extern    void    wink_sdwk_menu();
  14. /* ---------------------------------------------------------- */
  15.  
  16. extern int  strlen();
  17. extern void memset();
  18.  
  19. extern int  Get_key();
  20. extern int  getch();
  21. extern int  kbhit();
  22. extern void KYB_clic();
  23.  
  24. extern void Set_vram();
  25. extern void wrtstr();
  26. extern void Dsp_vram();
  27. extern void Dsp_vram_flash();
  28. extern void Dsp_wrt_flg();
  29. extern void Set_file_name();
  30. extern void ChgCol_wind();
  31.  
  32. extern int  save();
  33. extern int  File_sel();
  34. extern BOOL iskan();
  35.  
  36. extern void Cut_buf();
  37. extern void Ins_buf();
  38. extern void Del_buf();
  39. extern void Buf_init();
  40. extern int  New_wind();
  41. extern int  Del_wind();
  42. extern void ReSize_wind();
  43. extern LONG Line_ptr();
  44. extern LONG Undo_get();
  45. extern void Undo_put();
  46.  
  47. extern LONG Bak_line2();
  48. extern LONG Nxt_line2();
  49. extern LONG USerch();
  50.  
  51. extern void ASCII_code();
  52. extern void KANJI_code();
  53. extern void Printer_out();
  54.  
  55. extern char     *file_name;
  56. extern UCHAR    vram[];
  57. extern short    ReWrt_flg;
  58. extern short    dlp_flg,Wind_flg;
  59.  
  60.        int      Line_no=0;
  61.        short    Line_X=0,Line_Y=0;
  62.        int      Wrt_mode=FALSE,TAB_mode=0;
  63.        char     *SPCSTR="                                     ";
  64.        char     *FILEMEI="ファイル名 ";
  65. static int    Ins_flg=FALSE;
  66. static int    Endof_edit=FALSE;
  67. static UCHAR     sctmp[160]={ 0 };
  68. static UCHAR    rpsctmp[160]={ 0 };
  69. static UCHAR    rpdstmp[160]={ 0 };
  70.  
  71. LONG    Top_line(ptr)
  72. LONG    ptr;
  73. {
  74.     return Bak_line(Nxt_line(ptr));
  75. }
  76. char    *Dmy_form(p,i,ch1,ch2,ch3)
  77. char    *p;
  78. int    i,ch1,ch2,ch3;
  79. {
  80.     *(p++) = ch1; *(p++) = 0x1B;
  81.     while ( i-- > 0 ) {
  82.     *(p++) = ch2; *(p++) = 0x1B;
  83.     }
  84.     *(p++) = ch3; *(p++) = 0x1B; *p = '\0';
  85.     return p;
  86. }
  87. int    Yes_no(ttl)
  88. char    *ttl;
  89. {
  90.     int     len,x,ch,ec;
  91.     char    tmp[160];
  92.  
  93.     len = strlen(ttl) + 4; x = 36 - len / 2;
  94.     Dmy_form(tmp,len,0x98,0x95,0x99); 
  95.     wrtstr(tmp,x,8,0x02);
  96.  
  97.     Dmy_form(tmp,len,0x96,0x20,0x96); 
  98.     wrtstr(tmp,x,9,0x02);
  99.     wrtstr(tmp,x,10,0x02);
  100.     wrtstr(ttl,x+2,10,0x02);
  101.  
  102.     wrtstr(tmp,x,11,0x02);
  103.     wrtstr(tmp,x,12,0x02);
  104.     wrtstr("はい/Y  いいえ/N",28,12,0x02);
  105.  
  106.     wrtstr(tmp,x,13,0x02);
  107.     Dmy_form(tmp,len,0x9A,0x95,0x9B); 
  108.     wrtstr(tmp,x,14,0x02);
  109.  
  110.     /* --------------- FEP OFF   93.01.21 Pumpkin ------------- */
  111. #ifdef    TOWNS
  112.     KAN_disp(KAN_DISPOFF);
  113. #endif
  114.     /* ---------------------------------------------------------- */
  115.     ch = Get_key(&ec);
  116. #ifdef    TOWNS
  117.     Dsp_vram_flash();
  118.     /* --------------- FEP OFF   93.01.21 Pumpkin ------------- */
  119.     KAN_disp(KAN_DISPON);
  120.     /* ---------------------------------------------------------- */
  121. #endif
  122.     if ( ch == 'y' || ch == 'Y' || ec == 0x7300 )
  123.     return TRUE;
  124.     else
  125.     return FALSE;
  126. }
  127. int    Sel_menu(menu,x,y,old_no)
  128. char    *menu[];
  129. int    x,y,*old_no;
  130. {
  131.     int     i,mx,ch,ec,no,fg;
  132.     char    tmp[100];    /* RED2 Like  80 --> 100 に変更  HIKA */
  133.     int     nul_no[8],nul=0;
  134.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  135.     /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  136.      char    fststr[30];
  137.     /* ---------------------------------------------------------- */
  138.  
  139.     /* --------------- FEP OFF   93.01.21 Pumpkin ------------- */
  140. #ifdef    TOWNS
  141.     KAN_disp(KAN_DISPOFF);
  142. #endif
  143.     /* ---------------------------------------------------------- */
  144.  
  145.     i = strlen(menu[0]);
  146.     Dmy_form(tmp,i,0x98,0x95,0x99); 
  147.     wrtstr(tmp,x,y++,0x07);
  148.     no = *old_no;
  149.     for ( mx = 0 ; menu[mx] != NULL ; mx++ ) {
  150.     if ( menu[mx][0] == '\0' ) {
  151.         Dmy_form(tmp,i,0x93,0x95,0x92); 
  152.         nul_no[nul++] = mx;
  153.         if ( no >= mx ) no++;
  154.     } else {
  155.         sprintf(tmp,"\x96\x1B%s\x96\x1B",menu[mx]);
  156.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  157.         fststr[mx-nul] = menu[mx][0];
  158.     /* ---------------------------------------------------------- */
  159.     }
  160.     wrtstr(tmp,x,y+mx,0x07);
  161.     }
  162.     Dmy_form(tmp,i,0x9A,0x95,0x9B); 
  163.     wrtstr(tmp,x,y+mx,0x07);
  164.  
  165.     for ( ; ; ) {
  166.     if ( no >= 0 )
  167.         wrtstr(menu[no],x+1,y+no,0x14);
  168.     ch = Get_key(&ec);
  169.     /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  170.     /* --------------- FEP OFF   93.01.21 Pumpkin ------------- */
  171.         if ( ch == '\x1c' ) { /* → */
  172.         Dsp_vram_flash();
  173. #ifdef    TOWNS
  174.         KAN_disp(KAN_DISPON);
  175. #endif
  176.         return RIGHT;
  177.     }
  178.         if ( ch == '\x1d' ) { /* ← */
  179.         Dsp_vram_flash();
  180. #ifdef    TOWNS
  181.         KAN_disp(KAN_DISPON);
  182. #endif
  183.         return LEFT;
  184.     }
  185.         /* ---------------------------------------------------------- */
  186.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  187.         if ( ( ch >= 'A' && ch <= 'Z' ) || ( ch >= 'a' && ch <= 'z' ) ) {
  188.          for ( i = 0 ; i < mx-nul ; i++ ){
  189.              if ( ch == fststr[i] || ch == fststr[i] + 0x20 )
  190.                  ch = 0x31 + i;
  191.          }
  192.     }
  193.     /* ---------------------------------------------------------- */
  194.  
  195.     if ( no >= 0 )
  196.         wrtstr(menu[no],x+1,y+no,0x07);
  197.     if ( ch == ' ' || ch == '\x1F' || ec == 0x7200 ) {
  198.         if ( ++no >= mx )
  199.         no = ERR;
  200.         else if ( menu[no][0] == '\0' && ++no >= mx )
  201.         no = ERR;
  202.     } else if ( ch == '\x08' || ch == '\x1E' ) {
  203.         if ( --no < ERR )
  204.         no = mx - 1;
  205.         else if ( no >= 0 && menu[no][0] == '\0' && --no < ERR )
  206.         no = mx - 1;
  207.     } else if ( ch == '\x0D' || ec == 0x7300 ) {
  208.         fg = 0;
  209.         break;
  210.     } else if ( ec == 0x7200 || ec == 0x0100 || 
  211.                        (ec >= 0x5D00 && ec <= 0x6600) ) {
  212.         fg = 1;
  213.         break;
  214.     } else if ( ch >= '1' && ch <= '9' && (ch - '1') < mx ) {
  215.         no = ch - '1';
  216.         fg = 2;
  217.         break;
  218.     }
  219.     }
  220.     if ( fg != 2 ) {
  221.     if ( no >= 0 )
  222.         wrtstr(menu[no],x+1,y+no,0x14);
  223.     for ( i = 0,mx = no ; i < nul ; i++ ) {
  224.         if ( no >= nul_no[i] )
  225.         mx--;
  226.     }
  227.     no = mx;
  228.     }
  229. #ifdef    TOWNS
  230.     Dsp_vram_flash();
  231.     /* --------------- FEP OFF   93.01.21 Pumpkin ------------- */
  232.     KAN_disp(KAN_DISPON);
  233.     /* ---------------------------------------------------------- */
  234. #endif
  235.     *old_no = no;
  236.     if ( no == ERR || fg == 1 )
  237.     return ERR;
  238.     else
  239.     return FALSE;
  240. }
  241. UCHAR    *kanji_chk(str,len)
  242. UCHAR    *str;
  243. int    len;
  244. {
  245.     while ( len > 0 ) {
  246.     if ( iskanji(*str) && iskanji2(*(str+1)) ) {
  247.         str += 2;
  248.         len -= 2;
  249.     } else {
  250.         str++;
  251.         len--;
  252.     }
  253.     }
  254.     return str;
  255. }
  256.  
  257. /* ------------------ RED2 like 92/12/28 Pumpkin ---------------- */
  258.  
  259. extern void MOJI_input1Char(UCHAR *moji_area
  260.         ,unsigned int ky,int max_moji,int *lcur_x);
  261.  
  262. BOOL    _Input(UCHAR *arg,char *ttl,int sw)
  263. {
  264.     int        ch,ec,x,len;
  265.     int     Bk_X,Bk_Y;
  266.     BOOL    fg=FALSE;
  267.     char    tmp[80],tmp2[3];
  268.     int        lcur_x;
  269.  
  270.     arg[35] = 0;
  271.     sprintf(tmp,"%s%36s",ttl,"");
  272.     x = strlen(ttl) + 15;
  273.     Bk_X = Cur_X; Bk_Y = Cur_Y;
  274.     len = lcur_x = strlen(arg);
  275.     Cur_Y = (0 - OFF_Y);
  276.     wrtstr(tmp,15,0,0x07);
  277.     memset(arg+lcur_x,0,36-lcur_x);
  278.  
  279.     for ( ; ; ) {
  280.     Cur_X = x + lcur_x; ReWrt_flg = ERR;
  281.     strcpy(tmp,arg);
  282.     memset(tmp+len,' ',36-len);
  283.     tmp[36]=0;
  284.     wrtstr(tmp,x,0,0x07);
  285.  
  286.     if (lcur_x == len) {
  287.         tmp2[0] = 0xFE;
  288.         tmp2[1] = 0x1B;
  289.         tmp2[2] = 0;
  290.         wrtstr(tmp2,Cur_X,0,0x07);
  291.     }else{
  292.         if (iskanji(arg[lcur_x])) {
  293.             tmp2[0] = arg[lcur_x];
  294.             tmp2[1] = arg[lcur_x+1];
  295.             tmp2[2] = 0;
  296.         }else{
  297.             tmp2[0] = arg[lcur_x];
  298.             tmp2[1] = 0;
  299.         }
  300.         wrtstr(tmp2,Cur_X,0,0x17);
  301.     }
  302.  
  303.         ch = Get_key(&ec);
  304.  
  305.     MOJI_input1Char(arg,ch,36,&lcur_x);
  306.     len = strlen(arg);
  307.     if ( ch == '\x0D' || ec == 0x7300 )
  308.         break;
  309.     else if ( ch == '\x1B' || ec == 0x7200 ) {
  310.         fg = ERR;
  311.         break;
  312.     } else if ( sw == 1 && (ch == '\x1e' || ch == '\x1f') ) {
  313.         fg = ch;
  314.         break;
  315.     } else if ( ec == 0x4f04) {
  316.             lcur_x = 0;
  317.     } else if ( ec == 0x5104) {
  318.             lcur_x = strlen(arg);
  319.     } else if ( ch == '\x0B' ) {
  320.             arg[0] = '\0'; lcur_x = len = 0;
  321.     }
  322.     }
  323.     arg[len] = '\0';
  324.     memset(tmp,' ',51);
  325.     tmp[51] = '\0';
  326.     wrtstr(tmp,15,0,0x1F);
  327.     Cur_X = Bk_X; Cur_Y = Bk_Y;
  328.  
  329.     return fg;
  330. }
  331.  
  332. BOOL    Input(UCHAR *arg,char *ttl)
  333. {
  334.     return _Input(arg,ttl,0);
  335. }
  336. BOOL    Input2(UCHAR *arg,char *ttl)
  337. {
  338.     return _Input(arg,ttl,1);
  339. }
  340. /* -------------------------------------------------------------- */
  341. /**************
  342. BOOL    Input(arg,ttl)
  343. UCHAR    *arg;
  344. char    *ttl;
  345. {
  346.     int        ch,ec,x,len;
  347.     int     Bk_X,Bk_Y;
  348.     BOOL    fg=FALSE;
  349.     char    tmp[80];
  350.  
  351.     sprintf(tmp,"%s%36s",ttl,"");
  352.     x = strlen(ttl) + 15;
  353.     Bk_X = Cur_X; Bk_Y = Cur_Y;
  354.     Cur_Y = (0 - OFF_Y);
  355.     wrtstr(tmp,15,0,0x07);
  356.     for ( len = strlen(arg) ; ; ) {
  357.     arg[len] = 0xFE; arg[len+1] = 0x1B;
  358.     memset(arg+len+2,' ',34-len);
  359.     arg[34] = '\0';
  360.     Cur_X = x + len; ReWrt_flg = ERR;
  361.     wrtstr(arg,x,0,0x07);
  362.         ch = Get_key(&ec);
  363.     if ( ch != 0xFFFF && ch >= ' ' && len < 34 )
  364.         arg[len++] = ch;
  365.     else if ( ch == '\x0D' || ec == 0x7300 )
  366.         break;
  367.     else if ( ch == '\x1B' || ec == 0x7200 ) {
  368.         fg = ERR;
  369.         break;
  370.     } else if ( ch == '\x08' && len > 0 ) {
  371.         len--;
  372.         if ( (arg + len) != kanji_chk(arg,len) )
  373.         len--;
  374.     }
  375.     }
  376.     arg[len] = '\0';
  377.     memset(tmp,' ',50);
  378.     tmp[50] = 0;
  379.     wrtstr(tmp,15,0,0x1F);
  380.     Cur_X = Bk_X; Cur_Y = Bk_Y;
  381.     return fg;
  382. }
  383. *********/
  384. void    Line_set()
  385. {
  386.     LONG    p;
  387.  
  388.     for ( Line_no = 0, p = 0 ; p < top_ptr ; Line_no++ )
  389.         p = Nxt_line(p);
  390. }
  391. BOOL    Cut_buff(sp,ep)
  392. LONG    sp,ep;
  393. {
  394.     Undo_put(sp,ep - sp);
  395.     return FALSE;
  396. }
  397. void    ins_chr(str,len)
  398. UCHAR    *str;
  399. int    len;
  400. {
  401.     LONG    p;
  402.  
  403.     Ins_buf(ent_ptr,len,str);
  404.     ent_ptr += len; btm_ptr += len;
  405.     while ( (p = Nxt_line(lin_ptr)) <= ent_ptr ) {
  406.     if ( (lin_ptr = p) == btm_ptr )
  407.         break;
  408.     }
  409.     Wrt_flg = Wrt_mode = TRUE;
  410. }
  411. void    set_chr(str,len)
  412. UCHAR    *str;
  413. int    len;
  414. {
  415.     LONG    p;
  416.  
  417.     if ( Ins_flg == FALSE || ent_ptr == btm_ptr ) {
  418.     ins_chr(str,len);
  419.     return;
  420.     }
  421.  
  422.     p = Nxt_line(lin_ptr);
  423.     while ( len > 0 ) {
  424.     if ( ent_ptr == btm_ptr || *Cnv_ptr(ent_ptr) == '\x0D' ) {
  425.         ins_chr(str,len);
  426.         return;
  427.     } else {
  428.        while ( len > 0 ) {
  429.         if ( iskan(ent_ptr) != FALSE )
  430.             *Cnv_ptr(ent_ptr+1) = ' ';
  431.         *Cnv_ptr(ent_ptr++) = *(str++);
  432.         len--;
  433.         if ( ent_ptr == btm_ptr )
  434.             break;
  435.        }
  436.     }
  437.     if ( ent_ptr >= p ) {
  438.         lin_ptr = p;
  439.         p = Nxt_line(p);
  440.     }
  441.     }
  442.     Wrt_flg = Wrt_mode = TRUE;
  443. }
  444. LONG    Ent_pos()
  445. {
  446.     int        x;
  447.     LONG    p;
  448.  
  449.     for ( x = 0,p = lin_ptr ; x < Line_X && p < btm_ptr && 
  450.                     *Cnv_ptr(p) != '\x0D' ; ) {
  451.         if ( iskan(p) != FALSE ) {
  452.             x+=2; p+=2;
  453.     } else if ( *Cnv_ptr(p) == '\t' ) {
  454.             x = (((x + TAB) / TAB) * TAB);
  455.         p++;
  456.         } else {
  457.         x++; p++;
  458.     }
  459.     }
  460.     return p;
  461. }
  462. void    CR_put()
  463. {
  464.     if ( Ins_flg == FALSE || ent_ptr == btm_ptr ) {
  465.     ins_chr((UCHAR *)"\x0D\x0A",2);
  466.     return;
  467.     }
  468.     lin_ptr = ent_ptr = Nxt_line(lin_ptr);
  469. }
  470. void    TAB_put()
  471. {
  472.     int        i,j,x;
  473.     LONG    p;
  474.     UCHAR   tmp[40];
  475.  
  476.     if ( TAB_mode == 0 ) {
  477.     set_chr((UCHAR *)"\t",1);
  478.     return;
  479.     }
  480.  
  481.     for ( x = 0,p = lin_ptr ; p < ent_ptr ; ) {
  482.         if ( iskan(p) != FALSE ) {
  483.             x+=2; p+=2;
  484.     } else if ( *Cnv_ptr(p) == '\t' ) {
  485.             x = ((x + TAB) / TAB) * TAB;
  486.         p++;
  487.         } else {
  488.         x++; p++;
  489.     }
  490.     }
  491.     j = ((x + TAB) / TAB) * TAB - x;
  492.     for ( i = 0 ; i < j ; i++ )
  493.     tmp[i] = ' ';
  494.     set_chr(tmp,j);
  495. }
  496. void    Word_cut()
  497. {
  498.     int     i,ch;
  499.     LONG    p;
  500.     UCHAR   *s;
  501.  
  502.     for ( p = ent_ptr ; p != btm_ptr && 
  503.         ((ch = *Cnv_ptr(p)) == ' ' || ch == '\t') ; p++ );
  504.     s = sctmp; i = 0;
  505.     while ( i < 160 && 
  506.         p != btm_ptr && ((ch = *Cnv_ptr(p)) >= '0' || ch == '_') ) {
  507.     *(s++) = ch;
  508.     p++;
  509.     }
  510.     *s = '\0';
  511. }
  512. void    Word_serch()
  513. {
  514.     LONG    p;
  515.  
  516.     if ( sctmp[0] == '\0' )
  517.     return;
  518.     if ( (p = USerch(FALSE,ent_ptr,sctmp)) >= btm_ptr )
  519.     return;
  520.     if ( p == ent_ptr ) {
  521.     p += strlen(sctmp);
  522.         if ( (p = USerch(FALSE,p,sctmp)) >= btm_ptr )
  523.         return;
  524.     }
  525.     ent_ptr = p;
  526.     lin_ptr = Top_line(ent_ptr);
  527.     return;
  528. }
  529. void    Cur_up()
  530. {
  531.     int     i;
  532.  
  533.     if ( lin_ptr == 0 )
  534.     return;
  535.     if ( lin_ptr == btm_ptr && *Cnv_ptr(lin_ptr-1) != 0x0A ) {
  536.         lin_ptr = Bak_line(lin_ptr);
  537.         lin_ptr = Bak_line(lin_ptr);
  538.     } else 
  539.         lin_ptr = Bak_line2(lin_ptr);
  540.     ent_ptr = Ent_pos();
  541.     if ( lin_ptr < top_ptr ) {
  542.     for ( i = 5 ; top_ptr > 0 && i > 0 ; i-- ) {
  543.         top_ptr = Bak_line(top_ptr);
  544.         Line_no--;
  545.     }
  546.     }
  547. }
  548. void    Cur_down()
  549. {
  550.     if ( lin_ptr == btm_ptr )
  551.     return;
  552.     lin_ptr = Nxt_line2(lin_ptr);
  553.     ent_ptr = Ent_pos();
  554. }
  555. void    Scr_up()
  556. {
  557.     if ( lin_ptr == btm_ptr )
  558.     return;
  559.     top_ptr = Nxt_line(top_ptr);
  560.     lin_ptr = Nxt_line(lin_ptr);
  561.     ent_ptr = Ent_pos();
  562.     Line_no++;
  563. }
  564. void    Scr_down()
  565. {
  566.     if ( top_ptr == 0 ) {
  567.     Cur_up();
  568.         return;
  569.     }
  570.     top_ptr = Bak_line(top_ptr);
  571.     lin_ptr = Bak_line(lin_ptr);
  572.     ent_ptr = Ent_pos();
  573.     Line_no--;
  574. }
  575. void    PScr_up()
  576. {
  577.     int     i;
  578.  
  579.     for ( i=10 ; i > 0 ; i-- ) 
  580.     Scr_up();
  581. }
  582. void    PScr_down()
  583. {
  584.     int     i;
  585.  
  586.     for ( i=10 ; i > 0 ; i-- )
  587.     Scr_down();
  588. }
  589. void    Cur_rit()
  590. {
  591.     LONG    p;
  592.  
  593.     if ( ent_ptr == btm_ptr )
  594.     return;
  595.  
  596.     if ( iskan(ent_ptr) != FALSE ||
  597.     (*Cnv_ptr(ent_ptr) == '\x0D' && *Cnv_ptr(ent_ptr+1) == '\x0A') )
  598.     ent_ptr += 2;
  599.     else
  600.     ent_ptr++;
  601.     if ( (p = Nxt_line(lin_ptr)) <= ent_ptr )
  602.     lin_ptr = p;
  603. }
  604. void    Cur_left()
  605. {
  606.     LONG    p,s;
  607.  
  608.     if ( ent_ptr == 0 )
  609.     return;
  610.     if ( ent_ptr == lin_ptr ) {
  611.     if ( lin_ptr == top_ptr ) {
  612.         top_ptr = Bak_line(top_ptr);
  613.         Line_no--;
  614.     }
  615.     lin_ptr = Bak_line(lin_ptr);
  616.     }
  617.     for ( p = s = lin_ptr ; p < ent_ptr ; ) {
  618.         s = p;
  619.     if ( iskan(p) != FALSE ||
  620.         (*Cnv_ptr(p) == '\x0D' && *Cnv_ptr(p+1) == '\x0A' ) )
  621.         p+=2;
  622.     else
  623.         p++;
  624.     }
  625.     ent_ptr = s;
  626. }
  627. void    Cur_ltop()
  628. {
  629.     ent_ptr = lin_ptr;
  630. }
  631. void    Cur_lbtm()
  632. {
  633.     while ( ent_ptr != btm_ptr && *Cnv_ptr(ent_ptr) != '\x0D' )
  634.     Cur_rit();
  635. }
  636. void    Rit_word()
  637. {
  638.     while ( ent_ptr != btm_ptr && *Cnv_ptr(ent_ptr) >= '0' )
  639.     Cur_rit();
  640.     while ( ent_ptr != btm_ptr && *Cnv_ptr(ent_ptr) < '0' )
  641.     Cur_rit();
  642. }
  643. void    Left_word()
  644. {
  645.     if ( ent_ptr > 0 && *Cnv_ptr(ent_ptr) >= '0' && 
  646.              *Cnv_ptr(ent_ptr-1) >= '0' ) {
  647.         while ( ent_ptr > 0 && *Cnv_ptr(ent_ptr) >= '0' )
  648.         Cur_left();
  649.     } else {
  650.         while ( ent_ptr > 0 && *Cnv_ptr(ent_ptr) >= '0' )
  651.         Cur_left();
  652.         while ( ent_ptr > 0 && *Cnv_ptr(ent_ptr) < '0' )
  653.         Cur_left();
  654.         while ( ent_ptr > 0 && *Cnv_ptr(ent_ptr) >= '0' )
  655.         Cur_left();
  656.     }
  657.     if ( ent_ptr > 0 && *Cnv_ptr(ent_ptr) < '0' )
  658.     Cur_rit();
  659. }
  660. void    Del_chr()
  661. {
  662.     LONG    n;
  663.  
  664.     if ( ent_ptr == btm_ptr )
  665.     return;
  666.  
  667.     if ( iskan(ent_ptr) != FALSE || 
  668.     (*Cnv_ptr(ent_ptr) == '\x0D' && *Cnv_ptr(ent_ptr+1) == '\x0A' ) )
  669.     n = 2;
  670.     else
  671.     n = 1;
  672.  
  673.     Del_buf(ent_ptr,n);
  674.     btm_ptr -= n;
  675.     Wrt_flg = Wrt_mode = TRUE;
  676. }
  677. void    Del_line()
  678. {
  679.     LONG    n,p;
  680.  
  681.     if ( (p = Nxt_line(lin_ptr)) == lin_ptr )
  682.     return;
  683.     n = p - lin_ptr;
  684.     Cut_buff(lin_ptr,p);
  685.     Del_buf(lin_ptr,n);
  686.     btm_ptr -= n;
  687.     ent_ptr = Ent_pos();
  688.     Wrt_flg = Wrt_mode = TRUE;
  689. }
  690. void    Del_rit()
  691. {
  692.     LONG    n,p;
  693.  
  694.     if ( (p = Nxt_line(lin_ptr)) == lin_ptr )
  695.     return;
  696.     if ( (n = p - ent_ptr) <= 0 )
  697.     return;
  698.     Cut_buff(ent_ptr,p);
  699.     Del_buf(ent_ptr,n);
  700.     btm_ptr -= n;
  701.     Wrt_flg = Wrt_mode = TRUE;
  702. }
  703. void    Del_left()
  704. {
  705.     LONG    n;
  706.  
  707.     if ( lin_ptr == ent_ptr )
  708.     return;
  709.     n = ent_ptr - lin_ptr;
  710.     Cut_buff(lin_ptr,ent_ptr);
  711.     Del_buf(lin_ptr,n);
  712.     btm_ptr -= n;
  713.     ent_ptr = lin_ptr;
  714.     Wrt_flg = Wrt_mode = TRUE;
  715. }
  716. void    BS_chr()
  717. {
  718.     if ( ent_ptr == 0 )
  719.     return;
  720.     Cur_left();
  721.     Del_chr();
  722. }
  723. void    Undo_set()
  724. {
  725.     LONG    n;
  726.  
  727.     if ( (n = Undo_get(ent_ptr)) > 0L ) {
  728.         btm_ptr += n;
  729.         Wrt_flg = Wrt_mode = TRUE;
  730.     }
  731. }
  732. void    Del_dmy()
  733. {
  734.     LONG    p;
  735.  
  736.     if ( (p = Nxt_line(lin_ptr)) == lin_ptr )
  737.     return;
  738.     Cut_buff(lin_ptr,p);
  739.     p = ent_ptr;
  740.     ent_ptr = lin_ptr;
  741.     Undo_set();
  742.     ent_ptr = p;
  743. }
  744. void    Ins_line()
  745. {
  746.     Ins_buf(lin_ptr,2,"\x0D\x0A");
  747.     ent_ptr = lin_ptr;
  748.     btm_ptr += 2;
  749.     Wrt_flg = Wrt_mode = TRUE;
  750. }
  751. void    Cnt_dsp()
  752. {
  753.     if ( ++CONTRL > 2 )
  754.     CONTRL = 0;
  755. }
  756. void    Dsp_ins_mode()
  757. {
  758.     if ( Ins_flg == FALSE )
  759.     wrtstr("挿入",5,0,0x17);
  760.     else
  761.     wrtstr("上書",5,0,0x17);
  762. }
  763. void    Ins_sw()
  764. {
  765.     Ins_flg = (Ins_flg == FALSE ? TRUE : FALSE );
  766.     Dsp_ins_mode();
  767. }
  768. BOOL    Read_file(file)
  769. char    *file;
  770. {
  771.     int     n;
  772.     FILE    *fp;
  773.     LONG    p;
  774.     UCHAR   tmp[256];
  775.  
  776.     if ( (fp = fopen(file,"rb")) == NULL ) {
  777.     wrtstr("(ファイルが見当たりません)",30,1,0x12);
  778.         return ERR;
  779.     }
  780.  
  781.     wrtstr("(ファイル読み込み中)",32,1,0x05);
  782.     p = ent_ptr;
  783.     while ( (n = fread(tmp,1,256,fp)) > 0 ) {
  784.         if ( tmp[n-1] == '\x1A' ) n--;
  785.     Ins_buf(p,n,tmp);
  786.         btm_ptr += n;
  787.         p += n;
  788.         Wrt_flg = Wrt_mode = TRUE;
  789.     }
  790.     fclose(fp);
  791.     wrtstr(SPCSTR,30,1,0x1F);
  792.     return FALSE;
  793. }
  794. void    Wrt_file(sp,ep)
  795. LONG    sp,ep;
  796. {
  797.     int     n;
  798.     LONG    sz;
  799.     FILE    *fp;
  800.     UCHAR   tmp[256];
  801.  
  802.     wrtstr("(ファイルに抜き出します)",32,1,0x15);
  803.     tmp[0] = '\0';
  804.     if ( Input(tmp,FILEMEI) != FALSE )
  805.     goto END;
  806.     if ( (fp = fopen((char *)tmp,"wb")) == NULL ) {
  807.         wrtstr("(ファイルが作成出来ません)",30,1,0x12);
  808.     return;
  809.     }
  810.     for ( sz = ep - sp ; sz > 0 ; ) {
  811.     if ( sz < 256 ) n = sz; else n = 256;
  812.         Cut_buf(tmp,n,sp);
  813.     fwrite(tmp,1,n,fp);
  814.     sp += n;
  815.     sz -= n;
  816.     }
  817.     tmp[0] = 0x1A;
  818.     fwrite(tmp,1,1,fp);
  819.     fclose(fp);
  820.  
  821. END:
  822.     wrtstr(SPCSTR,30,1,0x1F);
  823. }
  824. void    Dsp_free()
  825. {
  826.     static int  Line_old=(-1);
  827.     static LONG Free_buf=(-1);
  828.     int    i;
  829.     char   tmp[30];
  830.  
  831.     if ( (i = Line_no + Line_Y) != Line_old ) {
  832.         Line_old = i;
  833.         sprintf(tmp,"[%06d Line]",Line_old+1);
  834.         wrtstr(tmp,67,0,0x1F);
  835.     }
  836.     if ( btm_ptr != Free_buf ) {
  837.         Free_buf = btm_ptr;
  838.         sprintf(tmp,"[%06ld Byte]",Free_buf);
  839.         wrtstr(tmp,67,1,0x1F);
  840.     }
  841. }
  842. void    Cur_top_file()
  843. {
  844.     lin_ptr = ent_ptr = top_ptr = 0;
  845.     Line_no = 0;
  846. }
  847. void    Cur_btm_file()
  848. {
  849.     int     i;
  850.  
  851. /* ------------------ bug fix  93.02.18 Pumpkin ---------------- */
  852. #ifdef TOWNS
  853.     i = 0x7FFFFFFF;
  854. #else
  855.     i = 0x7FFF;
  856. #endif
  857. /* -------------------------------------------------------------- */
  858. /**********
  859.     i = 0x7FFF;
  860. **********/
  861.     top_ptr = lin_ptr = ent_ptr = Line_ptr(&i);
  862.     Line_no = i;
  863.     for ( i = 10 ; top_ptr > 0 && i > 0 ; i-- ) {
  864.         top_ptr = Bak_line(top_ptr);
  865.     Line_no--;
  866.     }
  867. }
  868. void    Cmds_Q()
  869. {
  870.     int     ch;
  871.     unsigned ec;
  872.  
  873.     ch = Get_key(&ec); ec &= 0xff00;
  874.     switch(ec) {
  875.     case 0x1400: Cur_top_file(); break;
  876.     case 0x2C00: Cur_btm_file(); break;
  877.     case 0x1E00: Cur_ltop(); break;
  878.     case 0x2100: Cur_lbtm(); break;
  879.     }
  880. }
  881. void    Cmds_PF1()
  882. {
  883.     int    no;
  884.     UCHAR  *p;
  885.     static int   old_no=ERR;
  886.     static UCHAR tmp[160]={ 0 };
  887.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  888.      static char *menu[]={
  889.          "S: Save           1.保存して終了する   ",
  890.      "A: save All touch 2.全て保存して終了   ",
  891.      "",
  892.          "U: Up date        3.ファイルを更新する     ",
  893.          "C: Change name    4.ファイル名を変更する   ",
  894.      "",
  895.          "R: Read file      5.別のファイルを読み込む ",
  896.          "Q: Quit           6.編集を放棄する     ",
  897.      "X: eXit all       7.全ての編集を放棄   ",
  898.      "",
  899.          "O: Original file  8.再編集を行う       ",
  900.          "N: New window     9.新規に編集を行う   ",
  901.          NULL };
  902.     /* ---------------------------------------------------------- */
  903.     /***********************************************
  904.     static char *menu[]={
  905.         "1 保存して終了する  ",
  906.     "2 全て保存して終了  ",
  907.     "",
  908.         "3 ファイルを更新する    ",
  909.         "4 ファイル名を変更する  ",
  910.     "",
  911.         "5 ファイルを読み込む    ",
  912.         "6 編集を放棄する    ",
  913.     "7 全ての編集を放棄  ",
  914.     "",
  915.         "8 再編集を行う      ",
  916.         "9 新規に編集を行う  ",
  917.         NULL };
  918.     ************************************************/
  919. /* ------------------ New file  91.10.12 Pumpkin ---------------- */
  920.     unsigned int att=0,stat=0;
  921. /* -------------------------------------------------------------- */
  922.  
  923.     wrtstr(SPCSTR,30,1,0x1F);
  924. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  925.     switch (Sel_menu(menu,1,2,&old_no)) {
  926.         case FALSE:
  927.             break;
  928.         case LEFT: 
  929.                         Dsp_vram(vram);
  930.             CD_menu();
  931.             return;
  932.         case RIGHT:
  933.                         Dsp_vram(vram);
  934.             Cmds_PF2();
  935.             return;
  936.         default:
  937.             return;
  938.     }
  939. /*****
  940.     if ( Sel_menu(menu,1,2,&old_no) != FALSE )
  941.     return;
  942. *****/
  943. /* ---------------------------------------------------------- */
  944.  
  945.     no = old_no + 1;
  946.     if ( no == 1 || no == 2 ) {
  947.     do {
  948.         if ( Wrt_flg == FALSE ) {
  949.             wrtstr("(ファイルに変更がありません)",30,1,0x05);
  950.         } else {
  951.                 wrtstr("(書き込み中)",30,1,0x05);
  952.                 p = NULL;
  953.                 while ( save(p) != FALSE ) {
  954.                     wrtstr("(セ-ブ出来ません)",30,1,0x12);
  955.                     if ( Input(tmp,FILEMEI) != FALSE || 
  956.              File_sel(tmp) != FALSE ) {
  957.                         wrtstr(SPCSTR,30,1,0x1F);
  958.                         return;
  959.                     }
  960.                     p = tmp;
  961.                 }
  962.                 wrtstr("(書き込み終了)",30,1,0x05);
  963.         }
  964.     } while ( no == 2 && Del_wind() == FALSE );
  965.     } else if ( no == 3 ) {
  966.         if ( save(NULL) != FALSE )
  967.             wrtstr("(セ-ブ出来ません)",30,1,0x12);
  968.         return;
  969.     } else if ( no == 4 ) {
  970.         if ( Input(tmp,FILEMEI) != FALSE || File_sel(tmp) != FALSE )
  971.             return;
  972. /* ------------------ New file  91.10.12 Pumpkin ---------------- */
  973.     if (_dos_getfileattr((char *)tmp,&att) == 0 &&
  974.       Yes_no("同名のファイルが既にありますが よろしいですか?") == FALSE )
  975.                     return;
  976. /* -------------------------------------------------------------- */
  977.         Set_file_name(tmp);
  978. /* ------------------ RED2 like 92/01/31 Pumpkin ----------------- */
  979.         Wrt_flg = Wrt_mode = TRUE;
  980. /* -------------------------------------------------------------- */
  981.         return;
  982.     } else if ( no == 5 ) {
  983.         if ( Input(tmp,FILEMEI) != FALSE || File_sel(tmp) != FALSE )
  984.             return;
  985.         Read_file((char *)tmp);
  986.         return;
  987.    } else if ( no == 6 || no == 7 ) {
  988.     do {
  989.             if ( Wrt_flg != FALSE &&
  990.         Yes_no("ファイルに変更があります 編集を中断しますか?") == FALSE )
  991.                     return;
  992.             wrtstr("(編集を中断しました)",30,1,0x05);
  993.     } while ( no == 7 && Del_wind() == FALSE );
  994.     } else if ( no == 8 ) {
  995.     if ( file_name == NULL ) {
  996.         wrtstr("(ファイルが設定されてません)",30,1,0x12);
  997.         return;
  998.     }
  999.     if ( Wrt_flg != FALSE &&
  1000.         Yes_no("ファイルに変更があります 編集を放棄しますか?") == FALSE )
  1001.                 return;
  1002.     Del_buf(0l,btm_ptr);
  1003.     top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
  1004.     Line_no = 0;
  1005.     Wrt_flg = FALSE;
  1006.     Read_file(file_name);
  1007.     return;
  1008.     } else if ( no == 9 ) {
  1009. /* ------------------ New file  91.10.12 Pumpkin ---------------- */
  1010. /* ------------------ Debug  92.02.07 Pumpkin --------------- */
  1011.     if ( Input(tmp,FILEMEI) != FALSE ) return;
  1012.  
  1013.     att = 0;
  1014.     if (strlen(tmp) >= 2) {
  1015.         if (tmp[1] == 0x3a ) {
  1016.             if (tmp[0] >= 0x41 && tmp[0] <= 0x5a ) {
  1017.                 att = (unsigned int)(tmp[0] - 0x40);
  1018.             }
  1019.             if (tmp[0] >= 0x61 && tmp[0] <= 0x7a) {
  1020.                 att = (unsigned int)(tmp[0] - 0x60);
  1021.             }
  1022.         }
  1023.             if (diskReady(att) == ERR) {
  1024.             wrtstr("ディスクの準備ができていません",30,1,0x12);
  1025.             return;
  1026.         }
  1027.     } 
  1028.     stat = File_sel(tmp);
  1029.     if (stat == 2) {
  1030.         wrtstr("マッチするファイルがありません",30,1,0x12);
  1031.         return;
  1032.     }
  1033.     if (stat != FALSE) return;
  1034.  
  1035.     if ( Wrt_flg == FALSE && file_name == NULL ) {
  1036.        Buf_init(tmp);
  1037.        Set_file_name(tmp);
  1038.         Cur_top_file();
  1039.     } else {
  1040.         if ( New_wind(tmp) != FALSE ) {
  1041.             wrtstr("新規編集に失敗しました",30,1,0x12);
  1042.         }else{
  1043.             Cur_top_file();
  1044.         }
  1045.     }
  1046.     return;
  1047.  
  1048. /**********
  1049.     if ( Input(tmp,FILEMEI) != FALSE || File_sel(tmp) != FALSE )
  1050.         return;
  1051.  
  1052.     if ( Wrt_flg == FALSE && file_name == NULL ) {
  1053.        Buf_init(tmp);
  1054.        Set_file_name(tmp);
  1055.     } else if ( New_wind(tmp) != FALSE )
  1056.         wrtstr("新規編集に失敗しました",30,1,0x12);
  1057.     return;
  1058. ***********/
  1059. /* -------------------------------------------------------------- */
  1060.  
  1061.     }
  1062.     Endof_edit = TRUE;
  1063.     return;
  1064.  
  1065.  
  1066. }
  1067. LONG    Serch(ptr,str)
  1068. LONG    ptr;
  1069. UCHAR   *str;
  1070. {
  1071.     LONG    p;
  1072.     UCHAR   *s;
  1073.  
  1074.     while ( ptr < btm_ptr ) { 
  1075.     for ( p = ptr,s = str ; p < btm_ptr ; ) {
  1076.         if ( *s == '\0' )
  1077.         return ptr;
  1078.         if ( *Cnv_ptr(p++) != *(s++) )
  1079.         break;
  1080.     }
  1081.     ptr++;
  1082.     }
  1083.     return ptr;
  1084. }
  1085. LONG    USerch(sw,ptr,str)
  1086. int    sw;
  1087. LONG    ptr;
  1088. UCHAR   *str;
  1089. {
  1090.     int     cp,cs;
  1091.     LONG    p;
  1092.     UCHAR   *s;
  1093.  
  1094.     for ( ; ; ) {
  1095.     for ( p = ptr,s = str ; p < btm_ptr ; ) {
  1096.         if ( *s == '\0' )
  1097.         return ptr;
  1098.         cp = *Cnv_ptr(p++); cp = toupper(cp);
  1099.         cs = *(s++); cs = toupper(cs);
  1100.         if ( cp != cs )
  1101.         break;
  1102.     }
  1103.     if ( sw == FALSE ) {
  1104.         if ( ++ptr >= btm_ptr )
  1105.             return btm_ptr;
  1106.     } else if ( ptr-- <= 0 )
  1107.         return btm_ptr;
  1108.     }
  1109.     return ptr;
  1110. }
  1111. void    Cmds_PF2()
  1112. {
  1113.     int     i,j,no,ch,fg;
  1114.     UCHAR   *d,tmp[160];
  1115.     LONG    p,s;
  1116.     static int   old_no=ERR;
  1117. /* --------------- RED2 Like   92.12.30 Pumpkin ------------- */
  1118.     int        df,ec;
  1119. /* ---------------------------------------------------------- */
  1120.    /***********************************************
  1121.     static char  *menu[]={
  1122.         "1 文字列の検索(大小区別無し)",
  1123.         "2 文字列の置き換え(確認有り)",
  1124.         "3 文字列の置き換え          ",
  1125.     "",
  1126.         "4 指定行番号に移動          ",
  1127.         "5 ファイルの先頭に移動      ",
  1128.         "6 ファイルの最後に移動      ",
  1129.         NULL };
  1130.    ************************************************/
  1131.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  1132.      static char  *menu[]={
  1133.          "S: Search         1.文字列の検索           ",
  1134.          "R: Replace        2.文字列の置換(確認有り) ",
  1135.          "A: replace All    3.文字列の置換           ",
  1136.      "",
  1137.          "J: Jump           4.指定行番号に移動       ",
  1138.          "T: Top of file    5.ファイルの先頭に移動   ",
  1139.          "B: Bottom of file 6.ファイルの最後に移動   ",
  1140.      "",
  1141.          "Z: SideWork Menu  7.サイドワークメニュー   ",
  1142.          NULL };
  1143.    /* --------------------------------------------------------- - */
  1144.  
  1145.     wrtstr(SPCSTR,30,1,0x1F);
  1146. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  1147.     switch (Sel_menu(menu,10,2,&old_no)) {
  1148.         case FALSE:
  1149.             break;
  1150.         case LEFT: 
  1151.                         Dsp_vram(vram);
  1152.             Cmds_PF1();
  1153.             return;
  1154.         case RIGHT:
  1155.                         Dsp_vram(vram);
  1156.             Cmds_PF3();
  1157.             return;
  1158.         default:
  1159.             return;
  1160.     }
  1161. /*****
  1162.     if ( Sel_menu(menu,10,2,&old_no) != FALSE )
  1163.     return;
  1164. *****/
  1165. /* ---------------------------------------------------------- */
  1166.     no = old_no + 1;
  1167.  
  1168. /* --------------- RED2 Like   92.12.30 Pumpkin ------------- */
  1169.     if ( no == 1 ) {
  1170.     df = Input2(sctmp,"検索文字列 ");
  1171.         if ( df == ERR || sctmp[0] == '\0' ) return;
  1172.     if ( df == FALSE || df == '\x1F' ) fg = FALSE;
  1173.     if ( df == '\x1E' ) fg = TRUE;
  1174.     for ( ; ; ) {
  1175. kensaku_loop:
  1176.         p = USerch(fg,ent_ptr,sctmp);
  1177.         if ( p >= btm_ptr ) {
  1178.         df = Input2(sctmp,"見つかりません ");
  1179.             if ( df == ERR || sctmp[0] == '\0' ) return;
  1180.         if ( df == FALSE || df == '\x1F' ) {
  1181.             fg = FALSE;
  1182.             if ( ent_ptr < btm_ptr ) ent_ptr++;
  1183.         }
  1184.         if ( df == '\x1E' ) {
  1185.             fg = TRUE;
  1186.             if ( ent_ptr > 0 ) ent_ptr--;
  1187.         }
  1188.         goto kensaku_loop;
  1189.  
  1190.         }
  1191.  
  1192. /*****
  1193.         if ( Input(sctmp,"検索文字列 ") != FALSE || sctmp[0] == '\0' )
  1194.         return;
  1195.     for ( fg = FALSE ; ; ) {
  1196.         if ( (p = USerch(fg,ent_ptr,sctmp)) >= btm_ptr ) {
  1197.         wrtstr("(見つかりません)",30,1,0x15);
  1198.         return;
  1199.         }
  1200. *****/
  1201. /* ---------------------------------------------------------- */
  1202.         chk_ptr = ent_ptr = p; p += strlen(sctmp); cke_ptr = p;
  1203.         lin_ptr = Top_line(ent_ptr);
  1204.         for ( s = lin_ptr,i = 10 ; i > 0 ; i-- )
  1205.         s = Bak_line(s);
  1206.         while ( top_ptr < s ) {
  1207.         top_ptr = Nxt_line(top_ptr);
  1208.         Line_no++;
  1209.         }
  1210.         while ( top_ptr > s ) {
  1211.         top_ptr = Bak_line(top_ptr);
  1212.         Line_no--;
  1213.         }
  1214.         Set_vram();
  1215.         Dsp_vram(vram);
  1216.         Dsp_free();
  1217.         chk_ptr = cke_ptr = ERR;
  1218. /* ------------------ RED2 like 92/12/28 Pumpkin ---------------- */
  1219.         ch = Get_key(&ec);
  1220.         if ( ch == '\x1B'  || ec == 0x7200 ) 
  1221. /* -------------------------------------------------------------- */
  1222. /**********
  1223.         ch = getch();
  1224.         if ( ch == '\x1B' )
  1225. **********/
  1226.         return;
  1227.         else if ( ch == '\x0D' || ch == ' ' || ch == '\x1F' )
  1228.         fg = FALSE;
  1229.         else if ( ch == '\x08' || ch == '\x1E' )
  1230.         fg = TRUE;
  1231.  
  1232.         if ( fg == FALSE )
  1233.             ent_ptr = p;
  1234.         else if ( ent_ptr > 0 )
  1235.         ent_ptr--;
  1236.     }
  1237.     } else if ( no == 2 || no == 3 ) {
  1238.         if ( Input(rpsctmp,"現文字列 ") != FALSE )
  1239.         return;
  1240.         if ( Input(rpdstmp,"新文字列 ") != FALSE )
  1241.         return;
  1242.     if ( rpsctmp[0] == '\0' || rpdstmp[0] == '\0' )
  1243.         return;
  1244.     while ( ent_ptr < btm_ptr ) {
  1245.         if ( (p = Serch(ent_ptr,rpsctmp)) >= btm_ptr ) {
  1246.         wrtstr("(見つかりません)",30,1,0x15);
  1247.         return;
  1248.         }
  1249.         chk_ptr = ent_ptr = p; p += strlen(rpsctmp); cke_ptr = p;
  1250.         lin_ptr = Top_line(ent_ptr);
  1251.         for ( s = lin_ptr,i = 10 ; i > 0 ; i-- )
  1252.         s = Bak_line(s);
  1253.         while ( top_ptr < s ) {
  1254.         top_ptr = Nxt_line(top_ptr);
  1255.         Line_no++;
  1256.         }
  1257.         Set_vram();
  1258.         Dsp_vram(vram);
  1259.         Dsp_free();
  1260.         chk_ptr = cke_ptr = ERR;
  1261.         if ( no == 2 ) {
  1262.         i = getch();
  1263.         if ( i == '\x1B' )
  1264.             return;
  1265.         else if ( i == ' ' ) {
  1266.             ent_ptr = p;
  1267.             continue;
  1268.         }
  1269.         }
  1270.         if ( (i = strlen(rpsctmp)) > (j = strlen(rpdstmp)) ) {
  1271.         Del_buf(ent_ptr+j,(LONG)(i - j));
  1272.             btm_ptr -= (i - j);
  1273.         } else if ( i < j ) {
  1274.         Ins_buf(ent_ptr+i,(LONG)(j - i),rpdstmp);
  1275.             btm_ptr += (j - i);
  1276.         }
  1277.             for ( d = rpdstmp ; j-- > 0 ; )
  1278.         *Cnv_ptr(ent_ptr++) = *(d++);
  1279.         Wrt_flg = Wrt_mode = TRUE;
  1280.     }
  1281.     } else if ( no == 4 ) {
  1282.     tmp[0] = '\0';
  1283.     if ( Input(tmp,"行番号 ") == FALSE ) {
  1284.         i = atoi((char *)tmp) - 1;
  1285.         top_ptr = Line_ptr(&i); Line_no = i;
  1286.         lin_ptr = ent_ptr = top_ptr;
  1287.         for ( i = 10 ; i > 0 && top_ptr > 0 ; i-- ) {
  1288.         top_ptr = Bak_line(top_ptr);
  1289.         Line_no--;
  1290.         }
  1291.     }
  1292.     } else if ( no == 5 ) {
  1293.     Cur_top_file();
  1294.     } else if ( no == 6 ) {
  1295.     Cur_btm_file();
  1296.     } else if ( no == 7 ) {
  1297. #ifdef    FMR70
  1298.     cprintf("\x1B[24;1H");
  1299.     system("COMMAND.COM");
  1300.     Dsp_status();
  1301.     Dsp_free();
  1302. #endif
  1303. #ifdef    TOWNS
  1304. /* ------------------ SIDEWORK 92.01.31 Pumpkin -------------- */
  1305.     wink_sdwk_menu();
  1306. /******
  1307.         wrtstr("(実現不能?)",32,1,0x05);
  1308. ******/
  1309. /* ---------------------------------------------------------- */
  1310. #endif
  1311.     }
  1312. }
  1313.  
  1314. void    Cmds_PF3()
  1315. {
  1316.     static int  no=ERR,clic=0;
  1317.     int     i;
  1318.     UCHAR   tmp[80];
  1319.     char    *menu[8];
  1320.     char    ttl[5][80]; /* RED2 Like  60 -> 80 に変更  HIKA */
  1321.    /***********************************************
  1322.  
  1323.     sprintf(ttl[0],"1 TABコ-ド長の設定(現在%d個) ",TAB);
  1324.     sprintf(ttl[1],"2 TABコ-ドの展開を%s%s",
  1325.         TAB_mode != 0 ? "行わない":"行う",
  1326.         "            ");
  1327.     sprintf(ttl[2],"3 %sコ-ドの表示を%s%s",
  1328.         CONTRL == 0 ? "CR" : "CR&TAB",
  1329.         CONTRL != 2 ? "行う" : "行わない",
  1330.         "            ");
  1331.     sprintf(ttl[3],"4 キ-ボ-ド クリック音を%s%s",
  1332.         clic == 0 ? "鳴らす" : "消す",
  1333.         "             ");
  1334.     sprintf(ttl[4],"5 行番号表示を%s%s",
  1335.         dlp_flg == FALSE ? "する" : "しない",
  1336.         "             ");
  1337.    ***********************************************/
  1338.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  1339.      sprintf(ttl[0],"L: tab Length   1.TABコード長の設定(現在%d個)  ",TAB);
  1340.      sprintf(ttl[1],"T: Tab code     2.TABコ-ドの展開を%s%s",
  1341.          TAB_mode != 0 ? "行わない" : "行う",
  1342.          "             ");
  1343.      sprintf(ttl[2],"R: cR&tab code  3.%sコ-ドの表示を%s%s",
  1344.          CONTRL == 0 ? "CR" : "CR&TAB",
  1345.          CONTRL != 2 ? "行う" : "行わない",
  1346.          "             ");
  1347.      sprintf(ttl[3],"C: Click        4.キ-ボ-ド クリック音を%s%s",
  1348.          clic == 0 ? "鳴らす" : "消す",
  1349.          "              ");
  1350.      sprintf(ttl[4],"N: line No.     5.行番号表示を%s%s",
  1351.          dlp_flg == FALSE ? "する" : "しない",
  1352.          "              ");
  1353.     /* ---------------------------------------------------------- */
  1354.  
  1355.     i = strlen(ttl[0]); 
  1356.     ttl[1][i] = ttl[2][i] = ttl[3][i] = ttl[4][i] = '\0';
  1357.     menu[0] = ttl[0]; menu[1] = ttl[1]; menu[2] = "";
  1358.     menu[3] = ttl[2]; menu[4] = ttl[3]; 
  1359.     menu[5] = "";     menu[6] = ttl[4]; menu[7] = NULL;
  1360. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  1361.     switch (Sel_menu(menu,20,2,&no)) {
  1362.         case FALSE:
  1363.             break;
  1364.         case LEFT: 
  1365.                         Dsp_vram(vram);
  1366.             Cmds_PF2();
  1367.             return;
  1368.         case RIGHT:
  1369.                         Dsp_vram(vram);
  1370.             Cmds_PF4();
  1371.             return;
  1372.         default:
  1373.             return;
  1374.     }
  1375. /*****
  1376.     if ( Sel_menu(menu,20,2,&no) != FALSE )
  1377.     return;
  1378. *****/
  1379. /* ---------------------------------------------------------- */
  1380.  
  1381.     if ( no == 0 ) {
  1382.     tmp[0] = '\0';
  1383.     if ( Input(tmp,"TAB長(1-40) ") != FALSE )
  1384.         return;
  1385.     if ( (i = atoi((char *)tmp)) < 1 || i > 40 )
  1386.         return;
  1387.     TAB = i;
  1388.     } else if ( no == 1 ) {
  1389.     TAB_mode = (TAB_mode == 0 ? 1 : 0);
  1390.     } else if ( no == 2 ) {
  1391.     if ( ++CONTRL > 2 )
  1392.         CONTRL = 0;
  1393.     } else if ( no == 3 ) {
  1394.     KYB_clic(clic);
  1395.     clic = (clic == 0 ? 1 : 0);
  1396.     } else if ( no == 4 ) {
  1397.     dlp_flg = (dlp_flg == FALSE ? TRUE : FALSE);
  1398.     if ( dlp_flg != FALSE && Wind_flg == FALSE ) {
  1399.         Wind_flg = TRUE;
  1400.     }
  1401.     }
  1402. }
  1403. void    Cmds_PF4()
  1404. {
  1405.     static int   no=ERR;
  1406.  
  1407.   /******************************************
  1408.     static char  *menu[]={
  1409.         "1 ウインドサイズの変更 ",
  1410.         "2 文字表示色の変更     ",
  1411.     "",
  1412.     "3 ASCIIコ-ドの挿入    ",
  1413.     "4 漢字コ-ドの挿入     ",
  1414.     "",
  1415.     "5 編集バッファの印刷   ",
  1416.         NULL };
  1417.   ******************************************/
  1418.     /* --------------- RED2 Like   90.10.18 HIKA ---------------- */
  1419.      static char  *menu[]={
  1420.          "W: Window size  1.ウインドサイズの変更 ",
  1421.          "C: Color        2.文字表示色の変更     ",
  1422.      "",
  1423.      "A: Ascii code   3.ASCIIコ-ドの挿入    ",
  1424.      "K: Kanji code   4.漢字コ-ドの挿入     ",
  1425.      "",
  1426.      "P: Print out    5.編集バッファの印刷   ",
  1427.        NULL };
  1428.     /* ---------------------------------------------------------- */
  1429.  
  1430.     wrtstr(SPCSTR,30,1,0x1F);
  1431. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  1432.     switch (Sel_menu(menu,25,2,&no)) {
  1433.         case FALSE:
  1434.             break;
  1435.         case LEFT: 
  1436.                         Dsp_vram(vram);
  1437.             Cmds_PF3();
  1438.             return;
  1439.         case RIGHT:
  1440.                         Dsp_vram(vram);
  1441.             CD_menu();
  1442.             return;
  1443.         default:
  1444.             return;
  1445.     }
  1446. /*****
  1447.     if ( Sel_menu(menu,25,2,&no) != FALSE )
  1448.     return;
  1449. *****/
  1450. /* ---------------------------------------------------------- */
  1451.  
  1452.     if ( no == 0 )
  1453.     ReSize_wind();
  1454.     else if ( no == 1 )
  1455.     ChgCol_wind();
  1456.     else if ( no == 2 )
  1457.     ASCII_code();
  1458.     else if ( no == 3 )
  1459.     KANJI_code();
  1460.     else if ( no == 4 )
  1461.     Printer_out();
  1462. }
  1463. void    Cmds_PF6()
  1464. {
  1465.     int      ch,n,i,j,fg,no;
  1466.     unsigned ec;
  1467.     LONG     p,s,old_top;
  1468.     UCHAR    *d;
  1469.  
  1470.     chk_ptr = cke_ptr = ent_ptr; fg = FALSE;
  1471.     old_top = top_ptr; no = Line_no;
  1472.     wrtstr("範囲指定中",30,0,0x15);
  1473.     wrtstr(SPCSTR,30,1,0x1F);
  1474.     for ( ; ; ) {
  1475.         while ( kbhit() == FALSE );
  1476.  
  1477.         while ( kbhit() != FALSE ) {
  1478.         ch = Get_key(&ec);
  1479.         if ( ec == 0x0100 ) {
  1480.         goto ENDOF;
  1481.         } else if ( ec == 0x6200 || ec == 0x2410 ) {
  1482.         chk_ptr = cke_ptr = ent_ptr; no = Line_no;
  1483.         } else if ( ec == 0x6300 || ec == 0x1610 ) {
  1484.         if ( (n = cke_ptr - chk_ptr) > 0 ) {
  1485.                     if ( Cut_buff(chk_ptr,cke_ptr) != FALSE ) {
  1486.             if ( Yes_no("アンドゥ出来ません  削除を行いますか?") == FALSE )
  1487.                             goto ENDOF;
  1488.                     }
  1489.             Del_buf(chk_ptr,(LONG)(cke_ptr - chk_ptr));
  1490.                 btm_ptr -= n;
  1491.                 ent_ptr = chk_ptr;
  1492.             lin_ptr = Top_line(ent_ptr);
  1493.             if ( lin_ptr <= top_ptr ) {
  1494.             top_ptr = old_top;
  1495.             Line_no = no;
  1496.             }
  1497.             Wrt_flg = Wrt_mode = TRUE;
  1498.         }
  1499.         goto ENDOF;
  1500.         } else if ( ec == 0x6400 || ec == 0x2510 ) {
  1501.         if ( (cke_ptr - chk_ptr) > 0 )
  1502.             Cut_buff(chk_ptr,cke_ptr);
  1503.         goto ENDOF;
  1504.         } else if ( ec == 0x6500 ) {
  1505.         if ( (cke_ptr - chk_ptr) > 0 )
  1506.             Wrt_file(chk_ptr,cke_ptr);
  1507.         goto ENDOF;
  1508.         } else if ( ec == 0x5E00 ) {
  1509.         wrtstr("指定範囲内の文字列置き換え",30,1,0x15);
  1510.             if ( Input(rpsctmp,"現文字列 ") != FALSE )
  1511.                 goto ENDOF;
  1512.                 if ( Input(rpdstmp,"新文字列 ") != FALSE )
  1513.             goto ENDOF;
  1514.         ent_ptr = chk_ptr;
  1515.         lin_ptr = Top_line(ent_ptr);
  1516.         if ( lin_ptr <= top_ptr ) {
  1517.             top_ptr = old_top;
  1518.             Line_no = no;
  1519.         }
  1520.         old_top = cke_ptr;
  1521.         while ( ent_ptr < old_top ) {
  1522.             if ( (p = Serch(ent_ptr,rpsctmp)) >= old_top )
  1523.             goto ENDOF;
  1524.             chk_ptr = ent_ptr = p; p += strlen(rpsctmp); cke_ptr = p;
  1525.                 lin_ptr = Top_line(ent_ptr);
  1526.                 for ( s = lin_ptr,i = 10 ; i > 0 ; i-- )
  1527.             s = Bak_line(s);
  1528.             while ( top_ptr < s ) {
  1529.                 top_ptr = Nxt_line(top_ptr);
  1530.                 Line_no++;
  1531.                 }
  1532.                 Set_vram();
  1533.                 Dsp_vram(vram);
  1534.                 Dsp_free();
  1535.                 chk_ptr = cke_ptr = ERR;
  1536.             i = getch();
  1537.             if ( i == '\x1B' )
  1538.                 goto ENDOF;
  1539.             else if ( i == ' ' ) {
  1540.                 ent_ptr = p;
  1541.                 continue;
  1542.             }
  1543.                 if ( (i = strlen(rpsctmp)) > (j = strlen(rpdstmp)) ) {
  1544.                 Del_buf(ent_ptr+j,(LONG)(i - j));
  1545.                     btm_ptr -= (i - j);
  1546.                 } else if ( i < j ) {
  1547.                 Ins_buf(ent_ptr+i,(LONG)(j - i),rpdstmp);
  1548.                     btm_ptr += (j - i);
  1549.                 }
  1550.                     for ( d = rpdstmp ; j-- > 0 ; )
  1551.                 *Cnv_ptr(ent_ptr++) = *(d++);
  1552.         }
  1553.         goto ENDOF;
  1554.         }
  1555.         for ( i = 0 ; i < MOVECMDS && key_tbl[i].key_code != 0 ; i++ ) {
  1556.             if ( key_tbl[i].key_code == ec ) {
  1557.             (*(key_tbl[i].key_proc))();
  1558.             break;
  1559.         }
  1560.         }
  1561.         if ( fg == FALSE ) {
  1562.         if ( ent_ptr < chk_ptr ) {
  1563.             fg = TRUE;
  1564.             chk_ptr = ent_ptr;
  1565.             old_top = top_ptr;
  1566.             no = Line_no;
  1567.         } else
  1568.             cke_ptr = ent_ptr;
  1569.         } else {
  1570.         if ( ent_ptr > cke_ptr ) {
  1571.             fg = FALSE;
  1572.             cke_ptr = ent_ptr;
  1573.         } else {
  1574.             chk_ptr = ent_ptr;
  1575.             old_top = top_ptr;
  1576.             no = Line_no;
  1577.         }
  1578.         }
  1579.     }
  1580.         Set_vram();
  1581.         Dsp_vram(vram);
  1582.     Dsp_free();
  1583.     }
  1584. ENDOF:
  1585.     wrtstr(SPCSTR,30,0,0x1F);
  1586.     wrtstr(SPCSTR,30,1,0x1F);
  1587.     chk_ptr = cke_ptr = ERR;
  1588. }
  1589. BOOL    edit()
  1590. {
  1591.     int        i,n,ch,p;
  1592.     unsigned ec;
  1593.     UCHAR   tmp[40];    
  1594.  
  1595.     while ( kbhit() == 0 );
  1596.  
  1597.     Endof_edit = Wrt_mode = FALSE;
  1598.     for ( p = n = 0 ; Endof_edit == FALSE &&
  1599.               kbhit() != 0 && n < 10 ; n++ ) {
  1600.     ch = Get_key(&ec);
  1601.     for ( i = 0 ; key_tbl[i].key_code != 0 ; i++ ) {
  1602.         if ( key_tbl[i].key_code == ec ) {
  1603.         if ( p > 0 ) {
  1604.             set_chr(tmp,p);
  1605.             p = n = 0;
  1606.         }
  1607.         (*(key_tbl[i].key_proc))();
  1608.         break;
  1609.         }
  1610.     }
  1611.     if ( ch != 0xFFFF && key_tbl[i].key_code == 0 ) {
  1612.         tmp[p++] = ch;
  1613.         if ( p >= 30 ) {
  1614.         set_chr(tmp,p);
  1615.             p = 0;
  1616.         }
  1617.         n = 0;
  1618.     }
  1619.         Dsp_free();
  1620.     }
  1621.     if ( p > 0 )
  1622.     set_chr(tmp,p);
  1623.     Set_vram();
  1624.     Dsp_vram(vram);
  1625.     Dsp_wrt_flg();
  1626.     Dsp_free();
  1627.     if ( Endof_edit != FALSE )
  1628.     return TRUE;
  1629.     else
  1630.         return FALSE;
  1631. }
  1632.